from datetime import date
import pandas as pd

class Knowledge:
    knows=''
    date:date;
    file=''
    name=''

class Operate:

    def insert(self,know:Knowledge,sheet_name):
        # 读取现有数据
        df = pd.read_excel('student.xlsx', sheet_name=sheet_name)
        new_data = {}
        attributes = dir(know)
        # 过滤出用户定义的属性（过滤掉内置的方法和属性）
        instance_attributes = [attr for attr in attributes if
                               not callable(getattr(know, attr)) and not attr.startswith("__")]

        # 打印每个属性及其值
        for attr in instance_attributes:
            value = getattr(know, attr)
            new_data[attr]=value

        # 使用 append 方法添加新行
        updated_df = df.append(new_data, ignore_index=True)
        # 将更新后的 DataFrame 保存回 Excel 文件
        updated_df.to_excel('student.xlsx', sheet_name=sheet_name, index=False)